#!/usr/bin/env python

from ImgTiler import SplitImage
import cv2
import os
from fire import Fire

output_dir = "out"
os.makedirs(output_dir, exist_ok=True)


@Fire
def main(img, row, col, overlap):
    img = cv2.imread("1.jpg")
    grid = (row, col)
    show_rects = False
    show_image = False

    splitter = SplitImage(img, grid, overlap)
    tiles = splitter.split_image(show_rect=show_rects, show_tiles=show_image)

    # 保存图块
    for i, tile in enumerate(tiles):
        cv2.imwrite(os.path.join(output_dir, f"{i + 1}.jpg"), tile)

    print(f"已保存 {len(tiles)} 个图块到 '{output_dir}' 目录。")
